﻿
namespace CoreLims.Models.CoreLims
{
    /// <summary>
    /// age 测试用，可以不使用数据库。
    /// </summary>
    public class Age : IWorkFlow<Age>
    {
        public string Id { get; set; }

        public int Value { get; }

        public double Pay { get; set; }

        public string Name { get; }

        public double Bonus { get; set; }

        public Age(string name, int value, double pay, double bouns)
        {
            if (!IsValid(value))
                Value = -1;
            else
            {
                Value = value;
                Name = name;
                Pay = pay;
                Bonus = bouns;
            }
        }

        public Age(int value)
        {
            if (!IsValid(value))
                Value = -1;
            else
            {
                Value = value;
            }
        }

        public Age()
        {

        }

        public Age(string Id)
        {
            this.Id = Id;
            this.Value = 40;
            this.Name = "调用成功！";
            this.Pay = 2000;
        }

        public Age GetInstance(string Id)
        {
            return new Age(Id);
        }

        public Age AddPay(bool IsError, double addPay)
        {
            if (!IsError)
                this.Pay += addPay;
            return this;
        }

        public Age AddBouns(bool IsError, double addBouns)
        {
            if (!IsError)
                this.Bonus += addBouns;
            return this;
        }

        public static bool IsValid(int age)
            => (0 <= age && age < 120);

        /// <summary>
        /// 重载运算符，比较两个 Age 的大小。
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator <(Age l, Age r)
            => l.Value < r.Value;

        public static bool operator >(Age l, Age r)
            => l.Value > r.Value;

        /// <summary>
        /// 重载运算符，注意这个地方对传入的 int 值进行了一次转换，然后使用 Age 类进行比较。
        /// 这个方法就可以限定比较的参数的合理范围，编码错误时会立刻检查出来。
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator <(Age l, int r)
            => l < new Age(r);

        public static bool operator >(Age l, int r)
            => l > new Age(r);

    }
}
